<?php

namespace app\admin\controller\data;

use app\admin\service\DataTableService;
use app\admin\service\LinkTableService;
use ShidianUtil\Thinkphp\Response\ApiResponse;
use ShidianUtil\Utils\TimeUtil;
use think\APP;
use think\Request as Request;

/**
 * 核销板块数据日报
 * Class LinkTable
 * @package app\admin\controller\data
 */
class DataTable
{
    // 请求参数
    private Request $request;
    private DataTableService $dataTableService;

    public function __construct(Request $request, DataTableService $dataTableService)
    {
        $this->request = $request;
        $this->dataTableService = $dataTableService;
    }

    /**
     * @return ApiResponse
     * @url /data/data_table/index
     */
    public function index()
    {
        $request = $this->request;

        $defaultStartTime = TimeUtil::stamp(TimeUtil::MONTH, time());
        $defaultEndTime = TimeUtil::stamp(TimeUtil::MONTH, $defaultStartTime, false);

        $startTime = $request->param('startTime', $defaultStartTime);
        $endTime = $request->param('endTime', $defaultEndTime);

        $startTime = TimeUtil::stamp(TimeUtil::DAY, $startTime);
        $endTime = TimeUtil::stamp(TimeUtil::DAY, $endTime, false);

        return ApiResponse::success($this->dataTableService->index($startTime, $endTime));
    }
}
